/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#ifndef INCLUDE_VEC_CONVERSION
#define INCLUDE_VEC_CONVERSION

#include <basic_vec.h>





Inline uint32* f_array_多例索引(S_Array* a, uint32& v1Num) {
	S_UI32Array* v1Index = f_core_array_Index(a);

	uint32* 索引;

	if (v1Index) {
		v1Num = v1Index->count;
		索引 = v1Index->ptr_userData;
	}
	else {
		v1Num = a->count;
		索引 = nullptr;
	}

	return 索引;
}


Inline void f_array_释放UI32_2D(S_UI32Array2D* 网格元素) {
	for (uint32 i = 0; i < 网格元素->count; ++i) {
		//f_core_array_free((S_Array*)网格元素->ptr_userData[i]);
	}
	f_core_array_resize((S_Array*)网格元素, 0);
}

Inline void f_array_销毁UI32_2D(S_UI32Array2D* 网格元素) {
	for (uint32 i = 0; i < 网格元素->count; ++i) {
		//f_core_array_free((S_Array*)网格元素->ptr_userData[i]);
	}
	f_core_array_free((S_Array*)网格元素);
}









Inline S_UI32Array* f_array_UI32_alloc(float32 data) {
	S_UI32Array* v = (S_UI32Array*)f_core_array_new(1, sizeof(uint32), false, true);
	v->ptr_userData[0] = data;
	return v;
}

Inline S_UI32Array* f_array_UI32_alloc(const S_I8Array* data) {
	uint32 num = data->count;
	S_UI32Array* v = (S_UI32Array*)f_core_array_new(num, sizeof(uint32), false, true);
	for (uint32 i = 0; i < num; ++i) {
		v->ptr_userData[i] = data->ptr_userData[i];
	}
	return v;
}

Inline S_UI32Array* f_array_UI32_alloc(const S_I32Array* data) {
	uint32 num = data->count;
	S_UI32Array* v = (S_UI32Array*)f_core_array_new(num, sizeof(uint32), false, true);
	for (uint32 i = 0; i < num; ++i) {
		v->ptr_userData[i] = data->ptr_userData[i];
	}
	return v;
}

Inline S_UI32Array* f_array_UI32_alloc(const S_F32Array* data) {
	uint32 num = data->count;
	S_UI32Array* v = (S_UI32Array*)f_core_array_new(num, sizeof(uint32), false, true);

	for (uint32 i = 0; i < num; ++i) {
		v->ptr_userData[i] = data->ptr_userData[i];
	}
	return v;
}

Inline S_UI32Array* f_array_UI32_alloc(const S_UI32Array2D* data) {
	uint32 num = data->count;
	if (num) {
		return (S_UI32Array*)f_core_array_from((S_Array*)data->ptr_userData[0]);
	}
	return (S_UI32Array*)f_core_array_new(num, sizeof(uint32), false, true);
}




Inline S_I32Array* f_array_I32_alloc(float32 val) {
	S_I32Array* v = (S_I32Array*)f_core_array_new(1, sizeof(float32), false, true);
	v->ptr_userData[0] = val;
	return v;
}

Inline S_I32Array* f_array_I32_alloc(const S_I8Array* data) {
	uint32 num = data->count;
	S_I32Array* v = (S_I32Array*)f_core_array_new(num, sizeof(int32), false, true);
	for (uint32 i = 0; i < num; ++i) {
		v->ptr_userData[i] = data->ptr_userData[i];
	}
	return v;
}

Inline S_I32Array* f_array_I32_alloc(const S_UI32Array* data) {
	uint32 num = data->count;
	S_I32Array* v = (S_I32Array*)f_core_array_new(num, sizeof(int32), false, true);
	for (uint32 i = 0; i < num; ++i) {
		v->ptr_userData[i] = data->ptr_userData[i];
	}
	return v;
}

Inline S_I32Array* f_array_I32_alloc(const S_F32Array* data) {
	uint32 num = data->count;
	S_I32Array* v = (S_I32Array*)f_core_array_new(num, sizeof(int32), false, true);
	for (uint32 i = 0; i < num; ++i) {
		v->ptr_userData[i] = data->ptr_userData[i];
	}
	return v;
}




Inline S_F32Array* f_array_F32_alloc(const int32 data) {
	S_F32Array* v = (S_F32Array*)f_core_array_new(1, sizeof(float32), false, true);
	v->ptr_userData[0] = data;
	return v;
}

Inline S_F32Array* f_array_F32_alloc(const uint32 data) {
	S_F32Array* v = (S_F32Array*)f_core_array_new(1, sizeof(float32), false, true);
	v->ptr_userData[0] = data;
	return v;
}

Inline S_F32Array* f_array_F32_alloc(const float32 data) {
	S_F32Array* v = (S_F32Array*)f_core_array_new(1, sizeof(float32), false, true);
	v->ptr_userData[0] = data;
	return v;
}

Inline S_F32Array* f_array_F32_alloc(const S_I8Array* data) {
	uint32 num = data->count;
	S_F32Array* v = (S_F32Array*)f_core_array_new(num, sizeof(float32), false, true);

	for (uint32 i = 0; i < num; ++i) {
		v->ptr_userData[i] = data->ptr_userData[i];
	}
	return v;
}

Inline S_F32Array* f_array_F32_alloc(const S_I32Array* data) {
	uint32 num = data->count;
	S_F32Array* v = (S_F32Array*)f_core_array_new(num, sizeof(float32), false, true);

	for (uint32 i = 0; i < num; ++i) {
		v->ptr_userData[i] = data->ptr_userData[i];
	}
	return v;
}

Inline S_F32Array* f_array_F32_alloc(const S_UI32Array* data) {
	uint32 num = data->count;
	S_F32Array* v = (S_F32Array*)f_core_array_new(num, sizeof(float32), false, true);

	for (uint32 i = 0; i < num; ++i) {
		v->ptr_userData[i] = data->ptr_userData[i];
	}
	return v;
}

template<typename T>
Inline S_F32Array* f_array_F32_alloc_array(const T* data) {
	uint32 num = data->count;
	S_F32Array* v = (S_F32Array*)f_core_array_new(num, sizeof(float32), false, true);

	for (uint32 i = 0; i < num; ++i) {
		v->ptr_userData[i] = data->ptr_userData[i].x;
	}
	return v;
}




Inline S_BoolArray* f_array_Bool_alloc(const float32 data) {
	S_BoolArray* v = (S_BoolArray*)f_core_array_new(1, sizeof(bool), false, true);
	v->ptr_userData[0] = data;
	return v;
}
Inline S_BoolArray* f_array_Bool_alloc(const int32 data) {
	S_BoolArray* v = (S_BoolArray*)f_core_array_new(1, sizeof(bool), false, true);
	v->ptr_userData[0] = data;
	return v;
}
Inline S_BoolArray* f_array_Bool_alloc(const uint32 data) {
	S_BoolArray* v = (S_BoolArray*)f_core_array_new(1, sizeof(bool), false, true);
	v->ptr_userData[0] = data;
	return v;
}
Inline S_BoolArray* f_array_Bool_alloc(const S_I32Array* data) {
	uint32 num = data->count;
	S_BoolArray* v = (S_BoolArray*)f_core_array_new(num, sizeof(bool), false, true);
	for (uint32 i = 0; i < num; ++i) {
		v->ptr_userData[i] = data->ptr_userData[i];
	}
	return v;
}
Inline S_BoolArray* f_array_Bool_alloc(const S_UI32Array* data) {
	uint32 num = data->count;
	S_BoolArray* v = (S_BoolArray*)f_core_array_new(num, sizeof(bool), false, true);
	for (uint32 i = 0; i < num; ++i) {
		v->ptr_userData[i] = data->ptr_userData[i];
	}
	return v;
}
Inline S_BoolArray* f_array_Bool_alloc(const S_F32Array* data) {
	uint32 num = data->count;
	S_BoolArray* v = (S_BoolArray*)f_core_array_new(num, sizeof(bool), false, true);
	for (uint32 i = 0; i < num; ++i) {
		v->ptr_userData[i] = data->ptr_userData[i];
	}
	return v;
}




Inline S_I8Array* f_array_I8_alloc(const float32 data) {
	S_I8Array* v = (S_I8Array*)f_core_array_new(1, sizeof(int8), false, true);
	v->ptr_userData[0] = data;
	return v;
}
Inline S_I8Array* f_array_I8_alloc(const int8 data) {
	S_I8Array* v = (S_I8Array*)f_core_array_new(1, sizeof(int8), false, true);
	v->ptr_userData[0] = data;
	return v;
}
Inline S_I8Array* f_array_I8_alloc(const int32 data) {
	S_I8Array* v = (S_I8Array*)f_core_array_new(1, sizeof(int8), false, true);
	v->ptr_userData[0] = data;
	return v;
}
Inline S_I8Array* f_array_I8_alloc(const uint32 data) {
	S_I8Array* v = (S_I8Array*)f_core_array_new(1, sizeof(int8), false, true);
	v->ptr_userData[0] = data;
	return v;
}

Inline S_I8Array* f_array_I8_alloc(const S_I32Array* data) {
	uint32 num = data->count;
	S_I8Array* v = (S_I8Array*)f_core_array_new(num, sizeof(int8), false, true);

	for (uint32 i = 0; i < num; ++i) {
		v->ptr_userData[i] = data->ptr_userData[i];
	}
	return v;
}

Inline S_I8Array* f_array_I8_alloc(const S_F32Array* data) {
	uint32 num = data->count;
	S_I8Array* v = (S_I8Array*)f_core_array_new(num, sizeof(int8), false, true);

	for (uint32 i = 0; i < num; ++i) {
		v->ptr_userData[i] = data->ptr_userData[i];
	}
	return v;
}

Inline S_I8Array* f_array_I8_alloc(const S_UI32Array* data) {
	uint32 num = data->count;
	S_I8Array* v = (S_I8Array*)f_core_array_new(num, sizeof(int8), false, true);

	for (uint32 i = 0; i < num; ++i) {
		v->ptr_userData[i] = data->ptr_userData[i];
	}
	return v;
}



Inline S_Vec3Array* f_array_Vec3Array_alloc(float32 data) {
	S_Vec3Array* v = (S_Vec3Array*)f_core_array_new(1, sizeof(vec3), false, true);
	v->ptr_userData[0] = { data , data , data };
	return v;
}
Inline S_Vec3Array* f_array_Vec3Array_alloc(int32 data) {
	S_Vec3Array* v = (S_Vec3Array*)f_core_array_new(1, sizeof(vec3), false, true);
	v->ptr_userData[0] = { float32(data), float32(data), float32(data) };
	return v;
}

Inline S_Vec3Array* f_array_Vec3Array_alloc(vec3 data) {
	S_Vec3Array* v = (S_Vec3Array*)f_core_array_new(1, sizeof(vec3), false, true);
	v->ptr_userData[0] = { data.x, data.y, data.z };
	return v;
}

Inline S_Vec3Array* f_array_Vec3Array_alloc(vec4 data) {
	S_Vec3Array* v = (S_Vec3Array*)f_core_array_new(1, sizeof(vec3), false, true);
	v->ptr_userData[0] = { data.x, data.y, data.z };
	return v;
}

Inline S_Vec3Array* f_array_Vec3Array_alloc(const S_F32Array* data) {
	uint32 num = data->count;
	S_Vec3Array* v = (S_Vec3Array*)f_core_array_new(num, sizeof(vec3), false, true);

	for (uint32 i = 0; i < num; ++i) {
		auto 单个值 = float32(data->ptr_userData[i]);
		v->ptr_userData[i] = { 单个值 , 单个值 , 单个值 };
	}
	return v;
}

Inline S_Vec3Array* f_array_Vec3Array_alloc(const S_I32Array* data) {
	uint32 num = data->count;
	S_Vec3Array* v = (S_Vec3Array*)f_core_array_new(num, sizeof(vec3), false, true);

	for (uint32 i = 0; i < num; ++i) {
		auto 单个值 = float32(data->ptr_userData[i]);
		v->ptr_userData[i] = { 单个值 , 单个值 , 单个值 };
	}
	return v;
}

Inline S_Vec3Array* f_array_Vec3Array_alloc(const S_I8Array* data) {
	uint32 num = data->count;
	S_Vec3Array* v = (S_Vec3Array*)f_core_array_new(num, sizeof(vec3), false, true);

	for (uint32 i = 0; i < num; ++i) {
		auto 单个值 = float32(data->ptr_userData[i]);
		v->ptr_userData[i] = { 单个值 , 单个值 , 单个值 };
	}
	return v;
}

Inline S_Vec3Array* f_array_Vec3Array_alloc(const S_Vec2Array* data) {
	uint32 num = data->count;
	S_Vec3Array* v = (S_Vec3Array*)f_core_array_new(num, sizeof(vec3), false, true);

	for (uint32 i = 0; i < num; ++i) {
		v->ptr_userData[i] = { float32(data->ptr_userData[i].x), float32(data->ptr_userData[i].y), 0 };
	}
	return v;
}
Inline S_Vec3Array* f_array_Vec3Array_alloc(const S_iVec2Array* data) {
	uint32 num = data->count;
	S_Vec3Array* v = (S_Vec3Array*)f_core_array_new(num, sizeof(vec3), false, true);

	for (uint32 i = 0; i < num; ++i) {
		v->ptr_userData[i] = { float32(data->ptr_userData[i].x), float32(data->ptr_userData[i].y), 0 };
	}
	return v;
}

Inline S_Vec3Array* f_array_Vec3Array_alloc(const S_iVec3Array* data) {
	uint32 num = data->count;
	S_Vec3Array* v = (S_Vec3Array*)f_core_array_new(num, sizeof(vec3), false, true);

	for (uint32 i = 0; i < num; ++i) {
		v->ptr_userData[i] = { float32(data->ptr_userData[i].x), float32(data->ptr_userData[i].y), float32(data->ptr_userData[i].z) };
	}
	return v;
}

Inline S_Vec3Array* f_array_Vec3Array_alloc(const S_iVec4Array* data) {
	uint32 num = data->count;
	S_Vec3Array* v = (S_Vec3Array*)f_core_array_new(num, sizeof(vec3), false, true);

	for (uint32 i = 0; i < num; ++i) {
		v->ptr_userData[i] = { float32(data->ptr_userData[i].x), float32(data->ptr_userData[i].y), float32(data->ptr_userData[i].z) };
	}
	return v;
}




Inline void f_array_iVec2sfromI32s(S_iVec2Array* a, const S_I32Array* data) {
	uint32 num = data->count;
	f_core_array_resize((S_Array*)a, num);

	for (uint32 i = 0; i < num; ++i) {
		auto 单个值 = int32(data->ptr_userData[i]);
		a->ptr_userData[i].x = 单个值;
		a->ptr_userData[i].y = 单个值;
	}
}

Inline void f_array_iVec3fromI32_alloc(S_iVec3Array* a, const S_I32Array* data) {
	uint32 num = data->count;
	f_core_array_resize((S_Array*)a, num);

	for (uint32 i = 0; i < num; ++i) {
		auto 单个值 = int32(data->ptr_userData[i]);
		a->ptr_userData[i] = { 单个值 , 单个值 , 单个值 };
	}
}

Inline void f_array_iVec3fromI8_alloc(S_iVec3Array* a, const S_I8Array* data) {
	uint32 num = data->count;
	f_core_array_resize((S_Array*)a, num);

	for (uint32 i = 0; i < num; ++i) {
		auto 单个值 = int32(data->ptr_userData[i]);
		a->ptr_userData[i] = { 单个值 , 单个值 , 单个值 };
	}
}

Inline void f_array_iVec3fromF32_alloc(S_iVec3Array* a, const S_F32Array* data) {
	uint32 num = data->count;
	f_core_array_resize((S_Array*)a, num);

	for (uint32 i = 0; i < num; ++i) {
		auto 单个值 = int32(data->ptr_userData[i]);
		a->ptr_userData[i] = { 单个值 , 单个值 , 单个值 };
	}
}

Inline void f_array_iVec3fromVec3_alloc(S_iVec3Array* a, const S_Vec3Array* data) {
	uint32 num = data->count;
	f_core_array_resize((S_Array*)a, num);

	for (uint32 i = 0; i < num; ++i) {
		a->ptr_userData[i] = { int32(data->ptr_userData[i].x) , int32(data->ptr_userData[i].y) , int32(data->ptr_userData[i].z) };
	}
}


Inline void f_array_iVec4Array(S_iVec4Array* a, const S_I32Array* data) {
	uint32 num = data->count;
	f_core_array_resize((S_Array*)a, num);

	for (uint32 i = 0; i < num; ++i) {
		auto 单个值 = int32(data->ptr_userData[i]);
		a->ptr_userData[i] = { 单个值 , 单个值 , 单个值, 单个值 };
	}
}
Inline void f_array_iVec4Array(S_iVec4Array* a, const S_I8Array* data) {
	uint32 num = data->count;
	f_core_array_resize((S_Array*)a, num);

	for (uint32 i = 0; i < num; ++i) {
		auto 单个值 = int32(data->ptr_userData[i]);
		a->ptr_userData[i] = { 单个值 , 单个值 , 单个值, 单个值 };
	}
}
Inline void f_array_iVec4Array(S_iVec4Array* a, const S_F32Array* data) {
	uint32 num = data->count;
	f_core_array_resize((S_Array*)a, num);

	for (uint32 i = 0; i < num; ++i) {
		auto 单个值 = int32(data->ptr_userData[i]);
		a->ptr_userData[i] = { 单个值 , 单个值 , 单个值, 单个值 };
	}
}
Inline void f_array_iVec4Array(S_iVec4Array* a, const S_Vec3Array* data) {
	uint32 num = data->count;
	f_core_array_resize((S_Array*)a, num);

	for (uint32 i = 0; i < num; ++i) {
		a->ptr_userData[i] = { int32(data->ptr_userData[i].x) , int32(data->ptr_userData[i].y) , int32(data->ptr_userData[i].z), 0 };
	}
}



Inline void f_array_BoundingArray(vec3* a, const S_Cube& data) {
	vec3 size = data.size * 0.5f;

	a[0] = data.pos + vec3{-size.x, -size.y, -size.z};
	a[1] = data.pos + vec3{-size.x, size.y, -size.z};
	a[2] = data.pos + vec3{size.x, -size.y, -size.z};
	a[3] = data.pos + vec3{size.x, size.y, -size.z};

	a[4] = data.pos + vec3{-size.x, -size.y, size.z};
	a[5] = data.pos + vec3{-size.x, size.y, size.z};
	a[6] = data.pos + vec3{size.x, -size.y, size.z};
	a[7] = data.pos + vec3{size.x, size.y, size.z};
}

Inline void f_array_BoundingArray(S_Vec3Array* a, const S_CubeArray* data) {
	f_core_array_resize((S_Array*)a, data->count * 8);

	for (uint32 i = 0; i < data->count; ++i) {
		f_array_BoundingArray(&a->ptr_userData[i * 8], data->ptr_userData[i]);
	}
}

Inline void f_array_BoundingArray(S_Vec3Array* a, const S_Cube& data) {
	f_core_array_resize((S_Array*)a, 8);
	f_array_BoundingArray(a->ptr_userData, data);
}

Inline void f_array_BoundingArray(S_CubeArray* a, const S_Cube& data) {
	f_core_array_resize((S_Array*)a, 1);
	a->ptr_userData[0] = data;
}

Inline void f_array_BoundingArray(S_CubeArray* a, const S_Vec3Array* data) {
	uint32 num = data->count;
	if (num) {
		f_core_array_resize((S_Array*)a, num);

		for (uint32 i = 0; i < num; ++i) {
			a->ptr_userData[i].pos = data->ptr_userData[i];
			a->ptr_userData[i].size = { 1,1,1 };
		}
	}
	else {
		f_core_array_resize((S_Array*)a, 1);
		a->ptr_userData[0].pos = { 0, 0, 0 };
		a->ptr_userData[0].size = { 1, 1, 1 };
	}
}

Inline uint32 f_array_BoundingArray(S_CubeArray* 包围盒, const S_Vec3Array* 坐标, const S_Vec3Array* 大小, uint32 数量) {
	uint32 num = DEF_Max(坐标->count, 大小->count);
	num = DEF_Min(数量, num);

	bool 坐标多例 = 坐标->count >= num;
	bool 大小多例 = 大小->count >= num;

	f_core_array_resize((S_Array*)包围盒, num);
	for (uint32 i = 0; i < num; ++i) {
		包围盒->ptr_userData[i].pos = 坐标多例 ? 坐标->ptr_userData[i] : 坐标->ptr_userData[0];
		包围盒->ptr_userData[i].size = 大小多例 ? 大小->ptr_userData[i] : 大小->ptr_userData[0];
	}
	return num;
}







Inline void f_array_2DVec3from1DVec3_alloc(S_Vec3Array2D* v, S_Vec3Array* data) {
	f_core_array_resize((S_Array*)v, 1);
	v->ptr_userData[0] = (S_Vec3Array*)f_core_array_from((S_Array*)data);
}

Inline void f_array_2DiVec3from1DiVec3_alloc(S_iVec3Array2D* v, S_iVec3Array* data) {
	f_core_array_resize((S_Array*)v, 1);
	v->ptr_userData[0] = (S_iVec3Array*)f_core_array_from((S_Array*)data);
}










//Inline vec3 clamp(const vec3& x, const vec3& minVal, const vec3& maxVal) {
//	return { DEF_Min(DEF_Max(x.x, minVal.x), maxVal.x), DEF_Min(DEF_Max(x.y, minVal.y), maxVal.y), DEF_Min(DEF_Max(x.z, minVal.z), maxVal.z) };
//}

Inline ivec3 clamp(const ivec3& x, const ivec3& minVal, const ivec3& maxVal) {
	return { DEF_Min(DEF_Max(x.x, minVal.x), maxVal.x), DEF_Min(DEF_Max(x.y, minVal.y), maxVal.y), DEF_Min(DEF_Max(x.z, minVal.z), maxVal.z) };
}









Inline void f_JIT_坐标轴邻接数据(const S_Array* 坐标集, const ivec3& 坐标, const ivec3& 分辨率, S_Array* 邻接坐标) {
	uint32 元素大小 = f_core_array_get_elt_size(坐标集);
	f_core_array_resize(邻接坐标, 0);
	
	uint32 数据数量钳制 = 坐标集->count;

	ivec3 邻接轴[6] = {
		ivec3{-1,0,0},
		ivec3{1,0,0},
		ivec3{0,-1,0},
		ivec3{0,1,0},
		ivec3{0,0,-1},
		ivec3{0,0,1},
	};

	const ivec3 钳制分辨率 = 分辨率 - 1;
	//const ivec3 钳制分辨率 = 分辨率;

	uint32 层 = 分辨率.y * 分辨率.z;
	for (uint32 i = 0; i < 6; ++i) {
		ivec3 轴向 = 坐标 + 邻接轴[i];
		if (轴向.x < 0 || 轴向.x >= 分辨率.x) continue;
		if (轴向.y < 0 || 轴向.y >= 分辨率.y) continue;
		if (轴向.z < 0 || 轴向.z >= 分辨率.z) continue;
		//ivec3 轴向 = clamp(坐标 + 邻接轴[i], ivec3{ 0,0,0 }, 钳制分辨率);
		
		//if (轴向 != 坐标) {
		uint32 index = 层 * 轴向.z + (分辨率.x * 轴向.y) + 轴向.x;
		if(index < 数据数量钳制) f_core_array_push_back((S_Array*)邻接坐标, &坐标集->ptr_userData[index * 元素大小], false);
		//}
	}
}


template<typename T>
void f_array_赋值(T* a1, const T* a2) {
	uint32 num = a1->count;

	uint32 v1Num;
	uint32 v2Num;
	uint32* 索引1 = f_array_多例索引((S_Array*)a1, v1Num);
	uint32* 索引2 = f_array_多例索引((S_Array*)a2, v2Num);


	if (索引1 || 索引2) {
		num = v1Num;
		//bool 索引1多例 = v1Num >= num;
		bool 索引2多例 = v2Num >= num;
		num = v1Num;

		for (int64 i = 0; i < num; ++i) {
			uint32 i1;
			if (索引1) {
				//i1 = 索引1多例 ? 索引1[i] : 索引1[0];
				i1 = 索引1[i];
			}
			else {
				//i1 = 索引1多例 ? i : 0;
				i1 = i;
			}
			uint32 i2;
			if (索引2) {
				i2 = 索引2多例 ? 索引2[i] : 索引2[0];
			}
			else {
				i2 = 索引2多例 ? i : 0;
			}
			//a1->ptr_userData[索引1 ? i1 : i2] = a2->ptr_userData[i2];
			a1->ptr_userData[i1] = a2->ptr_userData[i2];
		}
	}
	else {
		bool 多例 = a2->count >= num;

		for (uint32 i = 0; i < num; ++i) {
			if (多例) a1->ptr_userData[i] = a2->ptr_userData[i];
			else a1->ptr_userData[i] = a2->ptr_userData[0];
		}
	}
}

template<typename T_Type, typename T>
void f_array_v2赋值(T* a1, const T* a2) {
	uint32 num = a1->count;

	uint32 v1Num;
	uint32 v2Num;
	uint32* 索引1 = f_array_多例索引((S_Array*)a1, v1Num);
	uint32* 索引2 = f_array_多例索引((S_Array*)a2, v2Num);

	if (索引1 || 索引2) {
		//num = DEF_Max(v1Num, v2Num);
		//bool 索引1多例 = v1Num >= num;
		bool 索引2多例 = v2Num >= num;
		num = v1Num;

		for (int64 i = 0; i < num; ++i) {
			uint32 i1;
			if (索引1) {
				//i1 = 索引1多例 ? 索引1[i] : 索引1[0];
				i1 = 索引1[i];
			}
			else {
				//i1 = 索引1多例 ? i : 0;
				i1 = i;
			}
			uint32 i2;
			if (索引2) {
				i2 = 索引2多例 ? 索引2[i] : 索引2[0];
			}
			else {
				i2 = 索引2多例 ? i : 0;
			}
			a1->ptr_userData[i1].x = T_Type(a2->ptr_userData[i2].x);
			a1->ptr_userData[i1].y = T_Type(a2->ptr_userData[i2].y);
		}
	}
	else {
		bool 多例 = a2->count >= num;

		for (uint32 i = 0; i < num; ++i) {
			if (多例) {
				a1->ptr_userData[i].x = T_Type(a2->ptr_userData[i].x);
				a1->ptr_userData[i].y = T_Type(a2->ptr_userData[i].y);
			}
			else {
				a1->ptr_userData[i].x = T_Type(a2->ptr_userData[0].x);
				a1->ptr_userData[i].y = T_Type(a2->ptr_userData[0].y);
			}
		}
	}
}

template<typename T_Type, typename T>
void f_array_v3赋值(T* a1, const T* a2) {
	uint32 num = a1->count;

	uint32 v1Num;
	uint32 v2Num;
	uint32* 索引1 = f_array_多例索引((S_Array*)a1, v1Num);
	uint32* 索引2 = f_array_多例索引((S_Array*)a2, v2Num);

	if (索引1 || 索引2) {
		num = v1Num;
		//num = DEF_Max(v1Num, v2Num);
		//bool 索引1多例 = v1Num >= num;
		bool 索引2多例 = v2Num >= num;
		
		for (int64 i = 0; i < num; ++i) {
			uint32 i1;
			if (索引1) {
				//i1 = 索引1多例 ? 索引1[i] : 索引1[0];
				i1 = 索引1[i];
			}
			else {
				//i1 = 索引1多例 ? i : 0;
				i1 = i;
			}
			uint32 i2;
			if (索引2) {
				i2 = 索引2多例 ? 索引2[i] : 索引2[0];
			}
			else {
				i2 = 索引2多例 ? i : 0;
			}
			a1->ptr_userData[i1].x = T_Type(a2->ptr_userData[i2].x);
			a1->ptr_userData[i1].y = T_Type(a2->ptr_userData[i2].y);
			a1->ptr_userData[i1].z = T_Type(a2->ptr_userData[i2].z);
		}
	}
	else {
		bool 多例 = a2->count >= num;

		for (uint32 i = 0; i < num; ++i) {
			if (多例) {
				a1->ptr_userData[i].x = T_Type(a2->ptr_userData[i].x);
				a1->ptr_userData[i].y = T_Type(a2->ptr_userData[i].y);
				a1->ptr_userData[i].z = T_Type(a2->ptr_userData[i].z);
			}
			else {
				a1->ptr_userData[i].x = T_Type(a2->ptr_userData[0].x);
				a1->ptr_userData[i].y = T_Type(a2->ptr_userData[0].y);
				a1->ptr_userData[i].z = T_Type(a2->ptr_userData[0].z);
			}
		}
	}
}







//template<typename T, typename 元素类型>
//元素类型 f_array_get第一个元素(T* a1) {
//	if (v->count) return v->ptr_userData[0];
//	return 0;
//}

//template<typename T, typename Te>
//Inline Te& f_array_get(T* a, ivec3 coord) {
//	auto* index = f_core_array_Index(a);
//	if (index) {
//		index->ptr_userData[0];
//	}
//	return a->ptr_userData[offset];
//}

//Inline void f_JIT_坐标轴邻接数据(const S_Array* 坐标集, const ivec3& 坐标, const ivec3& 分辨率, S_Array* 邻接坐标) {
//	uint32 元素大小 = f_core_array_get_elt_size(坐标集);
//	f_core_array_resize(邻接坐标, 0);
//
//	uint32 数据数量钳制 = 坐标集->count;
//
//	ivec3 邻接轴[6] = {
//		ivec3{-1,0,0},
//		ivec3{1,0,0},
//		ivec3{0,-1,0},
//		ivec3{0,1,0},
//		ivec3{0,0,-1},
//		ivec3{0,0,1},
//	};
//
//	const ivec3 钳制分辨率 = 分辨率 - 1;
//	//const ivec3 钳制分辨率 = 分辨率;
//
//	uint32 层 = 分辨率.y * 分辨率.z;
//	for (uint32 i = 0; i < 6; ++i) {
//		ivec3 轴向 = 坐标 + 邻接轴[i];
//		if (轴向.x < 0 || 轴向.x >= 分辨率.x) continue;
//		if (轴向.y < 0 || 轴向.y >= 分辨率.y) continue;
//		if (轴向.z < 0 || 轴向.z >= 分辨率.z) continue;
//		//ivec3 轴向 = clamp(坐标 + 邻接轴[i], ivec3{ 0,0,0 }, 钳制分辨率);
//
//		//if (轴向 != 坐标) {
//		uint32 index = 层 * 轴向.z + (分辨率.x * 轴向.y) + 轴向.x;
//		if (index < 数据数量钳制) f_core_array_push_back((S_Array*)邻接坐标, &坐标集->ptr_userData[index * 元素大小]);
//		//}
//	}
//}







#endif //INCLUDE_VEC_CONVERSION




